package com.bawei.module_base.net.util


import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory

import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit


object HttpUtils {
    private const val BASE_URL="http://10.59.9.24/"

//    返回一个Retrofit对象 请求数据和请求的结果
    private val retrofit: Retrofit by lazy {
        val okHttp=OkHttpClient.Builder()
            .connectTimeout(5,TimeUnit.SECONDS)
            .readTimeout(5,TimeUnit.SECONDS)
            .addInterceptor(HeaderInterceptor())
            .addInterceptor(HttpLoggingInterceptor()
                .setLevel(HttpLoggingInterceptor.Level.BODY))
            .build()
//    网络请求架构okhttp，rxjava，retrofit，
    Retrofit.Builder()
        .baseUrl(BASE_URL)
        .client(okHttp)
        .addConverterFactory(GsonConverterFactory.create())
        //异步各种线程间切换
        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
        .build()
}

    //返回给一个ApiService
    val apiService: ApiService by lazy {
        retrofit.create(ApiService::class.java)
    }


}